package org.example.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * JDBC查询语句
 * 查询所有用户的用户名、密码、年龄
 */
public class Demo04JDBC {
    public static void main(String[] args) {
        try ( Connection  connection = DBUtil.getConnection();){
            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery("SELECT username,password,age FROM user");
//            System.out.println(resultSet);// 打印的是地址
            while (resultSet.next()){
                String username = resultSet.getString("username");
                String password = resultSet.getString("password");
                int age = resultSet.getInt("age");
                System.out.println(username + "\t"+password +" \t" +age);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
      }
    }

